package com.tmeone.erpone.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tmeone.erpone.entity.JsonResult;
import com.tmeone.erpone.entity.TProductHandover;
import com.tmeone.erpone.entity.TProductionLine;
import com.tmeone.erpone.service.IAllProductionLineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class AllProductionLineController {
    @Autowired
    private IAllProductionLineService iAllProductionLineService;

    @RequestMapping("/allProductionLine")
    public JsonResult selectAllProductionLine(@RequestParam(value = "current",required = false,defaultValue = "1")Integer current,
                                              @RequestParam(value = "pageSize",required = false,defaultValue = "5")Integer pageSize){
        Page<TProductionLine> page = new Page<>(current, pageSize);
        IPage<TProductionLine> tProductionLineIPage = iAllProductionLineService.selectAllProductionLine(page);
        return new JsonResult(1,tProductionLineIPage);
    }
    @PostMapping("/allProductionLine")
    public JsonResult add(@RequestBody TProductionLine tProductionLine){
        int id = (int) (Math.random()*999999+100000);
        tProductionLine.setId(id);
        iAllProductionLineService.save(tProductionLine);
        return new JsonResult(1,null);
    }
    @PutMapping("/allProductionLine")
    public JsonResult update(@RequestBody TProductionLine tProductionLine){
        iAllProductionLineService.updateById(tProductionLine);
        return new JsonResult(1,null);
    }
    @DeleteMapping("/allProductionLine")
    public JsonResult delete(String id){
        iAllProductionLineService.removeById(id);
        return new JsonResult(1,null);
    }
}
